package com.project.util;

import lombok.Data;
import lombok.SneakyThrows;

import java.sql.*;

@Data
public class JdbcUtil {
    private String driver;
    private String url;
    private String password;
    private String username;


    @SneakyThrows
    public JdbcUtil(String driver, String url, String password, String username) {
        this.driver = driver;
        this.url = url;
        this.password = password;
        this.username = username;
        Class.forName(this.driver);
    }


    @SneakyThrows
    public Connection getConnection() {
        return DriverManager.getConnection(url, username, password);
    }


    @SneakyThrows
    public void close(Connection c, PreparedStatement p, ResultSet r) {
        if (c != null) c.close();
        if (p != null) p.close();
        if (r != null) r.close();
    }


}
